🧪 [Testing Improvement] Add edge case tests for percentile calculation - #189
🧪 [Testing Improvement] Add edge case tests for percentile calculation#189alvin000009238 wants to merge 1 commit into
Conversation
Co-authored-by: alvin000009238 <107313913+alvin000009238@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request adds unit tests to GradeAnalysisTest.kt to verify the behavior of the percentile function under various edge cases, such as invalid/missing inputs, rank exceeding count, and top rank. The reviewer suggested that the percentile function should return null instead of coercing the value when the rank exceeds the count, as a rank greater than the total count represents an invalid state.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| @Test | ||
| fun percentileCoercesToValidRangeWhenRankExceedsCount() { | ||
| assertEquals(100, percentile(40.0, 37)?.topPercent) | ||
| } |
There was a problem hiding this comment.
The test asserts that percentile(40.0, 37) returns a valid PercentileInfo with topPercent = 100. However, a rank of 40 in a class of 37 (rank > count) is an invalid state. Allowing this to succeed means the UI might display an invalid rank label like "40/37".
Consider whether percentile should return null when rank > count to prevent displaying invalid data. If so, you can update percentile in GradeAnalysis.kt as follows:
fun percentile(rank: Double?, count: Int?): PercentileInfo? {
if (rank == null || count == null || count <= 0 || rank > count) return null
// ...
}And update this test to assert assertNull instead.
| @Test | |
| fun percentileCoercesToValidRangeWhenRankExceedsCount() { | |
| assertEquals(100, percentile(40.0, 37)?.topPercent) | |
| } | |
| @Test | |
| fun percentileReturnsNullWhenRankExceedsCount() { | |
| assertNull(percentile(40.0, 37)) | |
| } |
There was a problem hiding this comment.
Pull request overview
This PR expands unit test coverage for percentile in GradeAnalysis.kt, documenting expected behavior for invalid inputs and boundary coercion, which helps prevent regressions in rank-to-percentile calculations used in grade analysis.
Changes:
- Add tests asserting
percentile(...)returnsnullwhenrank/countare missing or invalid (null, non-positive). - Add a boundary test ensuring
rank > countcoercestopPercentto100. - Add a boundary test ensuring very top ranks don’t round down below
1%(coerces to1).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🎯 What
Added edge case tests for the
percentilefunction inGradeAnalysis.ktwhich handles percentile info creation given rank and count inputs.📊 Coverage
rankandcount.rank>countverifying the coercion to100%.1%.✨ Result
Improved code coverage and reliability by fully documenting the expected outputs of invalid constraints on
percentileranking logic.PR created automatically by Jules for task 13288534687710996227 started by @alvin000009238